<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<jsp:useBean id="edittingOrg"
	class="team02.server.bean.OrganizationBean" scope="session"></jsp:useBean>
<jsp:useBean id="edittingOrgAdmin"
	class="team02.server.bean.UserBean" scope="page"></jsp:useBean>
<jsp:setProperty property="*" name="edittingOrg" />
<link href="${pageContext.request.contextPath}/css/org_manager.css"
	rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/css/add_new_org.css"
	rel="stylesheet" type="text/css" />
<script lang="javascript"
	src="${pageContext.request.contextPath}/js/org_edit.js"></script>
<script type="text/javascript">
function convert_date() {
	if(!checkpassword())return false;
	var str = document.getElementById("expired").value;
	var dt = new Date(str);
	document.getElementById("expiredDate").value=dt.getTime();

}
function error()
{
	alert("編集できませんでした");
}
function checkpassword() {
	if (document.getElementById("password").value != document.getElementById("confirmPassword").value) {
		alert("パスワードと確認パスワードが違う");
		return false;
	}
	return true;
}
</script>
<%
	//権限をチェック
	if (userBean.getAccessLevel() != 1 || request.getMethod() == "GET") {
		response.sendRedirect("404.html");
		return;
	}
	if (request.getParameterMap().containsKey("btn")) {
		if (edittingOrg.save() == 0)
		{
			response.sendRedirect("org_manager.t02");
		}
	else{
%>
			<script>error();</script>
<%
		}
	} else {
			edittingOrg.setAlias(request.getParameter("selected_id"));
			edittingOrg.load();
	}
%>
<div class="menu1"><%@include file="/jsputils/menu.jsp"%>
	<div class = "greeting_message">
		<%@include file="/jsputils/greeting.jsp"%>
	</div>
</div>
<div class="container">
<form action="" method="post" name="form" id="form">
	<div class="menu">
		<p class="menu_label">団体情報を編集</p>
	</div>
	<table class="content_table">
		<tr>
			<td>
				<p class="label">団体名：</p>
			</td>
			<td>
				<p class="input">
					<input required="required" type="text" name="name"
						value="${edittingOrg.name }" />
				</p>
			</td>
		</tr>
		<tr>
			<td>
				<p class="label">Alias ：</p>
			</td>
			<td>
				<p class="input">
					<input required="required" type="text" name="alias" disabled="disabled"
						value="${edittingOrg.alias }" />
				</p>
			</td>
		</tr>
		<tr>
			<td>
				<p class="label">期限日：</p>
			</td>
			<td>
				<p class="input">
					<input required="required" type="date" id="expired" name="expired"  class="{validate:{required:true, date:true}}"
						value="${edittingOrg.getExpiredDateString() }" />
					<input type="hidden" name="expiredDate" id="expiredDate" value=""/>
				</p>
			</td>
		</tr>
		<tr>
			<td>
				<p class="label">アドレス：</p>
			</td>
			<td>
				<p class="input">
					<input type="text" name="address" required="required"
						value="${edittingOrg.address }" />
				</p>
			</td>
		</tr>

		<tr>
			<td>
				<p class="label">モバイル</p>
			</td>
			<td>
				<p class="input">
					<input type="tel" name="phone" required="required" value="${edittingOrg.phone }" />
				</p>
			</td>
		</tr>
		<tr>
			<td>
				<p class="label">管理者名 ：</p>
			</td>
			<td>
				<p class="input">
					<input required="required" type="text" name="adminname"
						value="${edittingOrg.adminname }" />
				</p>
			</td>
		</tr>
		<tr>
			<td>
				<p class="label">ログイン名 ：</p>
			</td>
			<td>
				<p class="input">
					<input type="text" required="required" name="username"
						value="${edittingOrg.username }"/>
				</p>
			</td>
		</tr>
		<tr>
			<td>
				<p class="label">パスワード：</p>
			</td>
			<td>
				<p class="input">
					<input required="required" type="password" name="password" id="password"
						value="${edittingOrg.password }" />
				</p>
			</td>
		</tr>

		<tr>
			<td>
				<p class="label">パスワード再入力 ：</p>
			</td>
			<td>
				<p class="input">
					<input required="required" type="password" id="confirmPassword"
						name="orgConfirmPassword" value="${edittingOrg.password }" />
				</p>
			</td>
		</tr>
		<tr>
			<td>
				<p class="label">メール：</p>
			</td>
			<td>
				<p class="input">
					<input type="email" name="email" required="required" value="${edittingOrg.email }" />
				</p>
			</td>


		<tr>
			<td>
				<p class="label">説明：</p>
			</td>
			<td>
				<p class="input">
					<input type="text" name="description" required="required"
						value="${edittingOrg.description }" />
				</p>
			</td>
		</tr>
				<tr>
			<td>
				<p class="submit" style="text-align: right;">
					<input type="submit" formaction="" name="btn" value="保存" onclick="return convert_date()"/>
				</p>
			</td>
			<td style="text-align: left;">
				<a href="org_manager.t02">キャンセル</a>
			</td>
		</tr>
	</table>
</form>
</div>
